﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Tasks;
using Mogubang_Sl.Core;
using Mogubang_Sl.Utils;

namespace Mogubang_Sl.Pages
{
    public partial class ConfigPage : PhoneApplicationPage
    {
        public ConfigPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            this.btnMusic.IsChecked = StageManager.Instance.IsPlayBackground;
            this.btnSound.IsChecked = StageManager.Instance.IsPlaySound;
        }

        private void btnSound_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            StageManager.Instance.IsPlaySound = this.btnSound.IsChecked.Value;
            SoundManager.PlayEffect(SoundManager.clickbutton);
        }

        private void btnMusic_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            SoundManager.PlayEffect(SoundManager.clickbutton);
            StageManager.Instance.IsPlayBackground = this.btnMusic.IsChecked.Value;
            if (StageManager.Instance.IsPlayBackground)
            {
                AudioPlayHelper.PlayBackground();
            }
            else
            {
                AudioPlayHelper.StopBackground();
            }
        }

        private void btnContactUs_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            SoundManager.PlayEffect(SoundManager.clickbutton);
            EmailComposeTask emailComposeTask = new EmailComposeTask();

            emailComposeTask.Subject = "Suggestions for the Diamond Kingdom";
            emailComposeTask.Body = "Suggestion：";
            emailComposeTask.To = "studio77@126.com";

            emailComposeTask.Show();
        }

        private void btnReturn_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            SoundManager.PlayEffect(SoundManager.clickbutton);
            if (this.NavigationService.CanGoBack)
            {
                this.NavigationService.GoBack();
            }
            else
            {
                this.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));
            }
        }
    }
}